﻿using System;
using System.Collections.Generic;
using System.Text;
using PS.DBUtility;
using System.Data;
using System.Data.SqlClient;

namespace PS.DAL
{
    /// <summary>
    /// 数据访问类:BearingInfo 20110907 lxf
    /// </summary>
    public partial class BearingInfo
    {
        public BearingInfo() { }

        #region

        /// <summary>
        /// 分页查询信息 
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="Factory"></param>
        /// <param name="ShortType"></param>
        /// <param name="InnerDiameter"></param>
        /// <param name="OuterDiameter"></param>
        /// <param name="Thinkness"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public DataSet GetList(string Model, string Factory, string ShortType, string InnerDiameter, string OuterDiameter, string Thinkness, long pageSize, long pageIndex, out long totalCount)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from dbo.EquipBearingPara where 1=1 ");
            if (!string.IsNullOrEmpty(Model))
            {
                strSql.Append(" and (OldModel like '%").Append(Model).Append("%' or NewModel like '%").Append(Model).Append("%' or ReferModel like '%").Append(Model).Append("%') ");
            }
            if (!string.IsNullOrEmpty(Factory))
            {
                strSql.Append(" and Factory like '%").Append(Factory).Append("%'");
            }
            if (!string.IsNullOrEmpty(ShortType))
            {
                strSql.Append(" and ShortType like '%").Append(ShortType).Append("%'");
            }
            if (!string.IsNullOrEmpty(InnerDiameter))
            {
                strSql.Append(" and InnerDiameter like '%").Append(InnerDiameter).Append("%'");
            }
            if (!string.IsNullOrEmpty(OuterDiameter))
            {
                strSql.Append(" and OuterDiameter like '%").Append(OuterDiameter).Append("%'");
            }
            if (!string.IsNullOrEmpty(Thinkness))
            {
                strSql.Append(" and Thinkness like '%").Append(Thinkness).Append("%'");
            }
            strSql.Append("  order by EquipBearingParaID");

            string totalSql = PageSplitHelper.GetTotalSql(strSql.ToString());
            totalCount = long.Parse(DbHelperSQL.ExecuteScalar(totalSql).ToString());

            string pageSql = PageSplitHelper.GetPageSql(strSql.ToString(), pageSize, pageIndex, totalCount);

            return DbHelperSQL.Query(pageSql);
        }


        /// <summary>
        /// 得到一条数据
        /// </summary>
        public DataSet GetOne(int EquipBearingParaID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select p.EquipBearingParaID,BearingParaCode,InnerDiameter,OuterDiameter,Thinkness,OldModel,NewModel,ReferModel,Factory,LongType,p.ShortType,SpecialPara,Memo");
            strSql.Append(" ,Image1,Image2,Image3,Image4,Image5,Image6 ");
            strSql.Append("from dbo.EquipBearingPara p left join dbo.EquipBearingExpandPara e on p.ShortType=e.ShortType where 1=1 ");
            strSql.Append(" and p.EquipBearingParaID=@EquipBearingParaID ");
            SqlParameter[] parameters = {
                    new SqlParameter("@EquipBearingParaID", SqlDbType.Int,4)};
            parameters[0].Value = EquipBearingParaID;
            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }

        /// <summary>
        /// 获取生产厂家
        /// </summary>
        /// <returns></returns>
        public DataSet getFactory()
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select distinct Factory from dbo.EquipBearingPara ");

            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取类型
        /// </summary>
        /// <returns></returns>
        public DataSet getType()
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" select EquipBearingExpandParaID,ShortType,Memo,Image1,Image2,Image3,Image4,Image5,Image6 from dbo.EquipBearingExpandPara ");

            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion
    }
}
